package com.shilan.administrator.qintfm.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.shilan.administrator.qintfm.beans.RecommendResult;
import com.shilan.administrator.qintfm.fragment.tablayoutFragment.RecommendViewPageFragment;

import java.util.List;

/**
 * Created by dllo on 16/1/22.
 */
public class RecommendViewPagerAdapter extends FragmentPagerAdapter {
    //轮播图适配器
    private List<RecommendResult.FocusImagesEntity.ListEntity> list;

//    public List<RecommendResult.FocusImagesEntity.ListEntity> getList() {
//        return list;
//    }

    public void addData(List<RecommendResult.FocusImagesEntity.ListEntity> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public RecommendViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        RecommendResult.FocusImagesEntity.ListEntity listEntity
                = list.get(position % list.size());
        String imgUrl = listEntity.getPic();
        return RecommendViewPageFragment.getInstance(imgUrl,position % list.size(),list);
    }

    @Override
    public int getCount() {
        return list != null && list.size() > 0 ? Integer.MAX_VALUE : 0;
    }
}
